package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyTeacher(@RequestBody CourseTeacherVO courseTeacherVO) {
        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.vo2to(courseTeacherVO);
        Long companyId = SecurityUtil.getCompanyId();
        CourseTeacherDTO teacherDTO = courseTeacherService.createOrModifyTeacher(courseTeacherDTO, companyId);
        return teacherDTO;
    }

    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void removeTeacher(@PathVariable("courseBaseId") Long courseBaseId, @PathVariable("courseTeacherId") Long courseTeacherId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.removeTeacher(courseBaseId,courseTeacherId,companyId);
    }
}
